package com.splunk.hiring.imov.controller.mvc;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.splunk.hiring.imov.entity.Movie;
import com.splunk.hiring.imov.entity.MovieDetail;
import com.splunk.hiring.imov.entity.Tag;
import com.splunk.hiring.imov.entity.dto.MovieDetailDTO;
import com.splunk.hiring.imov.persist.db.MovieDao;
import com.splunk.hiring.imov.persist.db.TagDao;
import com.splunk.hiring.imov.service.MovieDetailService;

@Controller
public class MovieController {
	
	@Autowired
	MovieDao movieDao;
	
	@Autowired
	TagDao tagDao;
	
	@Autowired
	MovieDetailService movieDetailService;
	
	@RequestMapping(value = "/movie", method = RequestMethod.GET)
	public String getMovieDetails(@RequestParam Long movieId,Map<String, Object> model){
		Movie movie = movieDao.getMovieById(movieId);
		MovieDetail movieDetail = movieDetailService.getMovieDetail(movie);
		MovieDetailDTO movieDetailDTO = new MovieDetailDTO(movieDetail);
		List<Tag> tags = tagDao.getTagsByMovieId(movieId);
		model.put("movie", movieDetailDTO);
		model.put("tags",tags);
		
		return "imovdetail";
	}
	
	
}
